﻿using System;
using CoreTypes;
using System.Custom.Window;
using System.Drawing;
using System.Windows.Forms;

namespace OscarServiceTransport
{
   public partial class OscarDriverSettings : Window
   {
      CommunicationServiceObject FCommObj;

      public OscarDriverSettings(CommunicationServiceObject commObj)
      {
         InitializeComponent();

         FCommObj = commObj;

         Icon = (Icon)ResourceWrapper.GetObject("Gear");
      }

      private void buttonOk_Click(object sender, EventArgs e)
      {
         if (textBoxHost.Text != FCommObj.DefaultConfig.Host ||
             textBoxPort.Text != FCommObj.DefaultConfig.Port.ToString())
         {
            MessageBox.Show(ResourceWrapper.GetString("S_You_must_reconnect"), Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
         }

         FCommObj.DefaultConfig.Host = textBoxHost.Text;
         FCommObj.DefaultConfig.Port = ushort.Parse(textBoxPort.Text);

         FCommObj.FireSettingsChanged();

         Close();
      }
      private void buttonProxy_Click(object sender, EventArgs e)
      {
         FCommObj.Communicator.ShowSettings("Network");
      }
      private void buttonCancel_Click(object sender, EventArgs e)
      {
         Close();
      }
      private void buttonDefaults_Click(object sender, EventArgs e)
      {
         textBoxHost.Text = CommunicationServiceObject.AolLoginServerHost;
         textBoxPort.Text = CommunicationServiceObject.AolLoginServerPort.ToString();
      }
      private void window_VisibleChanged(object sender, EventArgs e)
      {
         if (Visible)
         {
            textBoxHost.Text = FCommObj.DefaultConfig.Host;
            textBoxPort.Text = FCommObj.DefaultConfig.Port.ToString();
         }
      }
   }
}
